#ifndef _STREAM_REDIRECTOR_H_
#define _STREAM_REDIRECTOR_H_

#include <iostream>
#include <fstream>


using namespace std;

// 
// This class can be used to temporarily redirect at run time the 
// output
//
class StreamRedirector
{
public:
    StreamRedirector(std::ostream & inOriginal, std::ostream & inRedirect) :
        mOriginal(inOriginal),
        mOldBuffer(inOriginal.rdbuf(inRedirect.rdbuf()))
    { }

    virtual ~StreamRedirector()
    {
      // restore the original stream
      mOriginal.rdbuf(mOldBuffer);
    }    

private:
    StreamRedirector(const StreamRedirector&);
    StreamRedirector& operator=(const StreamRedirector&);

    std::ostream & mOriginal;
    std::streambuf * mOldBuffer;
};


#endif // _STREAM_REDIRECTOR_H_

// EOF
